package com.springboot.test.common.utils;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * redis工具类
 */
@Component
public class RedisUtils {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    public  void set(String key, String value){
        stringRedisTemplate.opsForValue().set(key,value);
    }

    public String get(String key){
        String s = stringRedisTemplate.opsForValue().get(key);
        return s;
    }

    public void expireMin(String key, String value,Long time){
        stringRedisTemplate.opsForValue().set(key,value,time, TimeUnit.MINUTES);
    }

    public void remove(String key){
        stringRedisTemplate.delete(key);
    }

}
